package com.example;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class PhoneActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText phonenumber;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.phonelocal);
        initView();
    }

    public void initView() {
       Button butt=findViewById(R.id.btphone);
       butt.setOnClickListener(this);
       phonenumber = findViewById(R.id.phone_number);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.btphone:
                String number = phonenumber.getText().toString();
                if(number.length()==11){
                Intent intent = new Intent(this, PhoneNumberResult.class);
                Bundle bundle = new Bundle();
                bundle.putString("number", number);
                intent.putExtras(bundle);
                startActivity(intent);}else{
                    Toast.makeText(this,"您输入号码长度有误，请重新输入",Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}
